var req = null ;//定一个XMLHttpReqeust;

window.onload=function(){
	$("userName").onblur=function(){
		
		var userName = document.getElementById("userName").value ;
		
		req = createXMLHttpRequest();
		//需要请求的地址，判断用户名是否存在
		var url = "NewsUserServlet?action=findUserName&userName="+userName;
		req.open("get",url);
		req.onreadystatechange=function(){
			if(req.responseText=='yes'){
				$("userNameMes").innerHTML="用户名已存在！";
			}else{
				$("userNameMes").innerHTML="恭喜可以注册！";
			}
			
		}
		
		req.send(null); //req.send();这时火狐会报错。发送数据
	}
}



/**
 * 得到一个ajax的请求对象
 * @returns
 */
function createXMLHttpRequest (){	
	var xmlHttp;	
	if(window.ActiveXObject){	//判断是否为IE
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest){		
		xmlHttp=new XMLHttpRequest();
	}		
	return xmlHttp;
}


function $(id){
	return document.getElementById(id);
}